#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > rsp_excipolar.info <<'%EOF%'
   rsp_excipolar
   -------------
   Molecule:         O3
   Wave Function:    MCSCF (CAS)
   Test Purpose:     Excited-state polarizability
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > rsp_excipolar.mol <<'%EOF%'
INTGRL
Excited state polarizability of ozone (exp geometry from Lanholt-Boernstein)

    1    2  X  Z      1.00D-12
        8.0   2    3    1    1    1
 O1    0.000000           0.000000           0.000000
 O2    2.05743749931276   1.24132156150274   0.0000000000000
    8    3
883.27286 0.0175506 0.0000000 0.00000000
133.12928 0.1228292 0.0000000 0.00000000
29.906408 0.4348836 0.0000000 0.00000000
7.9786772 0.5600108 0.0000000 0.00000000
16.194447 0.0000000 -0.113401 0.00000000
3.7800860 0.0000000 -0.177286 0.00000000
1.0709836 0.0000000 1.1504079 0.00000000
0.2838798 0.0000000 0.0000000 1.00000000
    5    3
16.194447 0.0685453 0.0000000
3.7800860 0.3312254 0.0000000
1.0709836 0.7346079 0.0000000
0.2838798 0.0000000 1.0000000
0.05                          1.000000
    1    1
0.05      1.000000
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > rsp_excipolar.dal <<'%EOF%'
**DALTON INPUT
.RUN RESPONSE
**WAVE FUNCTION
.HF
.MP2
.MCSCF
*SCF INPUT
.DOUBLY OCCUPIED
 6    4    1    1
*CONFIGURATION INPUT
.INACTIVE
 5 3 0 0
.ELECTRONS
 8
.CAS SPACE
 2 2 2 2
.SYMMET
 1
.SPIN MULT
 1
**RESPONS
*CUBIC
.DOUBLE RESIDUE
.DIPLEN
.BFREQ
 1
0.005
.ROOTS
   0 3 3 0
.MAXITO
 100
.MAX IT
 100
.MAXITP
 100
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >rsp_excipolar.check
cat >>rsp_excipolar.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# Basis set
CRIT1=`$GREP "O * 3 * 8\.0000 * 28 * 17 * \[8s5p1d\|3s3p1d\]" $log | wc -l`
CRIT3=`$GREP "total\: * 3 * 24\.0000 * 84 * 51" $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT3`
CTRL[1]=2
ERROR[1]="BASIS SET NOT READ CORRECTLY"

# Geometry
CRIT1=`$GREP "Total number of coordinates\: * 9" $log | wc -l`
CRIT2=`$GREP "1 * x * (0| )\.0000000000" $log | wc -l`
CRIT3=`$GREP "2 * y * (0| )\.0000000000" $log | wc -l`
CRIT4=`$GREP "3 * z * (0| )\.0000000000" $log | wc -l`
CRIT5=`$GREP "4 * x * 2\.0574374993" $log | wc -l`
CRIT6=`$GREP "5 * y * 1\.2413215615" $log | wc -l`
CRIT7=`$GREP "6 * z * (0| )\.0000000000" $log | wc -l`
CRIT8=`$GREP "7 * x * \-2\.0574374993" $log | wc -l`
CRIT9=`$GREP "8 * y * 1\.2413215615" $log | wc -l`
CRIT10=`$GREP "9 * z * (0| )\.0000000000" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10`
CTRL[2]=10
ERROR[2]="GEOMETRY NOT READ CORRECTLY"

# Symmetry
CRIT1=`$GREP "Number of coordinates in each symmetry\: * 3 * 3 * 2 * 1" $log | wc -l`
CRIT2=`$GREP "Number of orbitals in each symmetry\: * 20 * 16 * 9 * 6" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2`
CTRL[3]=2
ERROR[3]="SYMMETRY NOT CORRECT"

# SCF energy
CRIT1=`$GREP "Hartree\-Fock total energy *\: * \-223\.92150423" $log | wc -l`
TEST[4]=`expr	$CRIT1`
CTRL[4]=1
ERROR[4]="SCF ENERGY NOT CORRECT"

# MP2 energy
CRIT1=`$GREP "\= MP2 second order energy *\: * \-224\.4026357" $log | wc -l`
TEST[5]=`expr	$CRIT1`
CTRL[5]=1
ERROR[5]="MP2 ENERGY NOT CORRECT"

# MCSCF energy
CRIT1=`$GREP "Final MCSCF energy\: * \-224\.16254751(4|5)." $log | wc -l`
TEST[6]=`expr	$CRIT1`
CTRL[6]=1
ERROR[6]="MCSCF ENERGY NOT CORRECT"

# Resopnse setup
CRIT1=`$GREP "Excited state polarizability requested TPALP\=T" $log | wc -l`
TEST[7]=`expr	$CRIT1`
CTRL[7]=1
ERROR[7]="RESPONSE CALCULATION NOT SET UP CORRECTLY"

# Polarizabilities
CRIT1=`$GREP "\@ < e \| AB \| f > * \= * 0*\.7738" $log | wc -l`
CRIT2=`$GREP "\@ < e \| AB \| f > * \= * 1\.322" $log | wc -l`
CRIT3=`$GREP "\@ < e \| AB \| f > * \= * \-4\.57[78]" $log | wc -l`
CRIT4=`$GREP "\@ < e \| AB \| f > * \= * 28\.84" $log | wc -l`
CRIT5=`$GREP "\@ < e \| AB \| f > * \= * \-74\.7" $log | wc -l`
CRIT6=`$GREP "\@ < e \| AB \| f > * \= * \-28\.47" $log | wc -l`
CRIT7=`$GREP "\@ < e \| AB \| f > * \= * 0*\.0613" $log | wc -l`
CRIT8=`$GREP "\@ < e \| AB \| f > * \= * \-1\.300" $log | wc -l`
CRIT9=`$GREP "\@ < e \| AB \| f > * \= * \-1\.553" $log | wc -l`
CRIT10=`$GREP "\@ < e \| AB \| f > * \= * \-0*\.795" $log | wc -l`
CRIT11=`$GREP "\@ < e \| AB \| f > * \= * \-0*\.53[67]" $log | wc -l`
CRIT12=`$GREP "\@ < e \| AB \| f > * \= * \-59\.1" $log | wc -l`
CRIT13=`$GREP "\@ < e \| AB \| f > * \= * 6\.62" $log | wc -l`
CRIT14=`$GREP "\@ < e \| AB \| f > * \= * \-16\.2" $log | wc -l`
CRIT15=`$GREP "\@ < e \| AB \| f > * \= * \-40\.2" $log | wc -l`
CRIT16=`$GREP "\@ < e \| AB \| f > * \= * 0*\.850" $log | wc -l`
CRIT17=`$GREP "\@ < e \| AB \| f > * \= * 5\.01" $log | wc -l`
CRIT18=`$GREP "\@ < e \| AB \| f > * \= * \-40\.5" $log | wc -l`
TEST[8]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12 \+ \
		$CRIT13 \+ $CRIT14 \+ $CRIT15 \+ $CRIT16 \+ $CRIT17 \+ $CRIT18`
CTRL[8]=18
ERROR[8]="POLARIZABILITIES NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 6 7 8
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
